<template>
  <div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="name" label="类别" width="200"></el-table-column>
      <el-table-column label="操作" width="188">
        <template slot-scope="scope">
          <el-button @click="edit(scope.row)" type="text" size="small">修改</el-button>
          <el-button @click="del(scope.row)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>

  export default {
    name: 'type',
    methods: {
      edit(row) {
        this.$router.push({
          path: '/updateType',
          query: {
            data: row
          }
        })
      },
      del(row) {
        let _this = this;
        _this.$confirm('此操作将永久删除数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$axios.get("/delType/" + row.tid).then(resp => {
            if (resp.data === 'success') {
              _this.$alert('删除成功！', '消息', {
                confirmButtonText: '确定',
                callback: action => {
                  window.location.reload()
                }
              })
            }
          })
        }).catch(() => {
          _this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });

      },

      // del(row) {
      //   let _this = this;
      //   this.$axios.get("/delType/" + row.tid).then(resp => {
      //     if (resp.data === 'success') {
      //       _this.$alert('删除成功！', '消息', {
      //         confirmButtonText: '确定',
      //         callback: action => {
      //           window.location.reload()
      //         }
      //       })
      //     }
      //   })
      // }
    },

    data() {
      return {
        tableData: [{
          tid: '',
          name: '',
          userid: '',
        }]
      }
    },

    created() {
      let _this = this;
      this.$axios.get("/type/"+this.$store.state.user.username).then(resp => {
        _this.tableData = resp.data;
        // console.log(_this.tableData );
      });
    }
  }
</script>

<style scoped>
</style>

